<?php 
class Home
{
	public function process()
	{
		$db = Mysql::instance();
		$result = $db->queryArray("select * from quotation order by rand() limit 0,1");

		if( count( $result ) > 0 )
		{
			return $result[0];
		}
		return false;
	}
	
	
	public function post()
	{
		if( ( Controller::$input['quotation']) )
		{
			$db = Mysql::instance();
			$row = array(
				'quotation' => Controller::$input['quotation'],
				'author' => ( isset( Controller::$input['author'] ) && Controller::$input['author'] )  ? Controller::$input['author'] : 'Anonymous',
				'detected_language' => detectLanguage(Controller::$input['quotation'] ),
				'description' => Controller::$input['description']
			);
			
			$sql = buildInsertQuery('quotation', $row );
			$result = $db->query( $sql );
			unset( $_SESSION['error']['home']['post'] );
		}
		else
		{
			$_SESSION['error']['home']['post'] = 'You are missing some fields! I think.';
		}
		header("Location:index.php");
	}
}


?>